<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商户接口配置')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-config-edit" th:object="${gatewayMerchantConfig}">
            <input name="id" th:field="*{id}" type="hidden">
            <input id ="mchId" name="mchId" th:field="*{merchantId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">商户编号：</label>
                <div class="col-sm-8">
                    <input id="merchantId" name="merchantId" th:field="*{merchantId}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">加密方式：</label>
                <div class="col-sm-8" >
                    <select id="encryptionType" name="encryptionType" th:with="type=${@dict.getType('gateway_encryption_type')}" class="form-control m-b">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{encryptionType}"></option>
					</select>
                </div>
            </div>
            <div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" th:field="*{remark}" type="text">
				</div>
			</div>
            <div class="form-group">
				<label class="col-sm-3 control-label">接口权限</label>
				<div class="col-sm-8">
					<div id="menuTrees" class="ztree"></div>
				</div>
			</div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ztree-js" />
    <script type="text/javascript">
        var prefix = ctx + "gateway/config";
        
        $(function() {
			var url = ctx + "gateway/api/apiMenuAuthTreeData?merchantId=" + $("#mchId").val();
			var options = {
				id: "menuTrees",
		        url: url,
		        check: { enable: true },
		        expandLevel: 0
		    };
			$.tree.init(options);
		});
        
        $("#form-config-edit").validate({
            focusCleanup: true
        });

        function edit() {
        	var id = $("input[name='id']").val();
        	var merchantId = $("input[name='merchantId']").val();
			var encryptionType = $("#encryptionType").find("option:selected").text();
			var remark = $("input[name='remark']").val();
			var menuIds = $.tree.getCheckedNodes();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "gateway/config/edit",
				data : {
					"id":id,
					"merchantId": merchantId,
					"encryptionType": encryptionType,
					"remark": remark,
					"menuIds": menuIds
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
        function submitHandler() {
        	if ($.validate.form()) {
	        	edit();
	        }
        }
    </script>
</body>
</html>